package net.homelinux.chaoswg.io.renga.krypto.operations.vector;

import net.homelinux.chaoswg.io.higherorderfunctions.AbstractBinaryFunction;
import net.homelinux.chaoswg.io.higherorderfunctions.BinaryFunction;
import net.homelinux.chaoswg.io.renga.krypto.datatypes.vectors.BitVector;

public class Xor extends AbstractBinaryFunction<BitVector, BitVector, BitVector> implements BinaryFunction<BitVector, BitVector, BitVector> {
    public final BitVector apply (final BitVector b0, final BitVector b1) throws IllegalArgumentException {
        if (b0.getSize () != b1.getSize()) {
            throw new IllegalArgumentException ();
        } else {
            final BitVector toReturn = new BitVector (b0.getSize());
            
            for (int i = 0; i < toReturn.getSize(); ++i) {
                toReturn.set (i, (b0.get(i) ^ b1.get(i)));
            }
            
            return toReturn;
        }
    }
    
    public String toString () {
        return "xor";
    }
}
